package jun.cli;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.HashMap;

import jun.app.TestDef;

public class TestCli2 {

	public static void main(String[] args) {
		String ip = "127.0.0.1";
		int port = 50080;
		Socket socket = null;
		try {
			// 创建Socket对象，连接
			socket = new Socket(ip, port);
			System.out.println("客户端启动成功, ip:"+ip+" 端口:"+port);

			// 从控制台获取数据
			BufferedReader sytIn = new BufferedReader(new InputStreamReader(System.in));
			
			// 创建PrintWriter对象，传输对象给server
			PrintWriter writer = new PrintWriter(socket.getOutputStream());

			// 获取从server传输过来的数据
			BufferedReader serIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			
			HashMap<String, Object> map = new HashMap<String, Object>();
			
			map.put(TestDef.Info.NAME, "三金");
			map.put(TestDef.Info.AGE, 24);
			
			String line = map.toString();
			
			while(!"end".equals(line)){
				writer.println(line);
				writer.flush();
				System.out.println("client发送数据:"+line);
				
				
				line = sytIn.readLine();
			}
			
			socket.close();
			sytIn.close();
			writer.close();
			serIn.close();
			
		} catch (Exception e) {
			System.out.println("客户端启动失败，端口:"+port+" Error:"+e);
		}
	}
}